home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 115_01.zip / ED5.C < prev    next >
Text File  |  1993-06-01  |  3KB  |  193 lines

  1. /* Screen editor:  output format module
  2.  *
  3.  * Source: ed5.c
  4.  * Version: March 6, 1981.
  5.  */
  6.  
  7.  
  8. /* Define variables global to this module */
  9.  
  10. /* define maximal length of a tab character */
  11.  
  12. int fmttab;
  13.  
  14. /* define the current device and device width */
  15.  
  16. int fmtdev;        /* device -- YES/NO = LIST/CONSOLE */
  17. int fmtwidth;        /* devide width.  LISTW/SCRNW1 */
  18.  
  19. /* fmtcol[i] is the first column at which
  20.  * buf[i] will be printed.
  21.  * fmtsub() and fmtlen() assume fmtcol[] is valid on entry.
  22.  */
  23.  
  24. int fmtcol[MAXLEN1];
  25.  
  26. /* direct output from this module to either the console or
  27.  * the list device.
  28.  */
  29.  
  30. fmtassn(listflag) int listflag;
  31. {
  32.     if (listflag==YES) {
  33.         fmtdev=YES;
  34.         fmtwidth=LISTW;
  35.     }
  36.     else {
  37.         fmtdev=NO;
  38.         fmtwidth=SCRNW1;
  39.     }
  40. }
  41.  
  42. /* adjust fmtcol[] to prepare for calls on
  43.  * fmtout() and fmtlen()
  44.  *
  45.  * NOTE:  this routine is needed as an efficiency
  46.  *        measure.  Without fmtadj(), calls on
  47.  *        fmtlen() become too slow.
  48.  */
  49.  
  50. fmtadj(buf,minind,maxind) char *buf; int minind,maxind;
  51. {
  52. int k;
  53.     /* line always starts at left margin */
  54.     fmtcol[0]=0;
  55.     /* start scanning at minind */
  56.     k=minind;
  57.     while (k<maxind) {
  58.         if (buf[k]==CR) {
  59.             break;
  60.         }
  61.         fmtcol[k+1]=fmtcol[k]+fmtlench(buf[k],fmtcol[k]);
  62.         k++;
  63.     }
  64. }
  65.  
  66. /* return column at which at which buf[i] will be printed */
  67.  
  68. fmtlen(buf,i) char *buf; int i;
  69. {
  70.     return(fmtcol[i]);
  71. }
  72.  
  73. /* print buf[i] ... buf[j-1] on current device so long as
  74.  * characters will not be printed in last column.
  75.  */
  76.  
  77. fmtsubs(buf,i,j) char *buf; int i, j;
  78. {
  79. int k;
  80.     if (fmtcol[i]>=fmtwidth) {
  81.         return;
  82.     }
  83.     outxy(fmtcol[i],outgety());    /* position cursor */
  84.     while (i<j) {
  85.         if (buf[i]==CR) {
  86.             break;
  87.         }
  88.         if (fmtcol[i+1]>fmtwidth) {
  89.             break;
  90.         }
  91.         fmtoutch(buf[i],fmtcol[i]);
  92.         i++;
  93.     }
  94.     outdeol();    /* clear rest of line */
  95. }
  96.  
  97. /* print string which ends with CR or EOS to current device.
  98.  * truncate the string if it is too long.
  99.  */
  100.  
  101. fmtsout(buf,offset) char *buf; int offset;
  102. {
  103. char c;
  104. int col,k;
  105.     col=0;
  106.     while (c=*buf++) {
  107.         if (c==CR) {
  108.             break;
  109.         }
  110.         k=fmtlench(c,col);
  111.         if ((col+k+offset)>fmtwidth) {
  112.             break;
  113.         }
  114.         fmtoutch(c,col);
  115.         col=col+k;
  116.     }
  117. }
  118.  
  119. /* return length of char c at column col */
  120.  
  121. fmtlench(c,col) char c; int col;
  122. {
  123.     if (c==TAB) {
  124.         /* tab every fmttab columns */
  125.         return(fmttab-(col%fmttab));
  126.     }
  127.     else if (c<32) {
  128.         /* control char */
  129.         return(2);
  130.     }
  131.     else {
  132.         return(1);
  133.     }
  134. }
  135.  
  136. /* output one character to current device.
  137.  * convert tabs to blanks.
  138.  */
  139.  
  140. fmtoutch(c,col) char c; int col;
  141. {
  142. int k;
  143.     if (c==TAB) {
  144.         k=fmtlench(TAB,col);
  145.         while ((k--)>0) {
  146.             fmtdevch(' ');
  147.         }
  148.     }
  149.     else if (c<32) {
  150.         fmtdevch('^');
  151.         fmtdevch(c+64);
  152.     }
  153.     else {
  154.         fmtdevch(c);
  155.     }
  156. }
  157.  
  158. /* output character to current device */
  159.  
  160. fmtdevch(c) char c;
  161. {
  162.     if (fmtdev==YES) {
  163.         syslout(c);
  164.     }
  165.     else {
  166.         outchar(c);
  167.     }
  168. }
  169.  
  170. /* output a CR and LF to the current device */
  171.  
  172. fmtcrlf()
  173. {
  174.     if (fmtdev==YES) {
  175.         syslout(CR);
  176.         syslout(LF);
  177.     }
  178.     else {
  179.         /* kludge: this should be in out module */
  180.         /* make sure out module knows position */
  181.         outxy(0,SCRNL1);
  182.         syscout(CR);
  183.         syscout(LF);
  184.     }
  185. }
  186.  
  187. /* set tabs at every n columns */
  188.  
  189. fmtset(n) int n;
  190. {
  191.     fmttab=max(1,n);
  192. }
  193.